<template>
	<view class="content">
		<view class="Popular">
			<view class="pop_content">
				
				<view class="pop_item" v-for="(item,index) in datalist" :key="index">
					<view class="top">
						<view class="left">
							<image :src="siteUrl+item.avatar" mode=""></image>
							<view class="text">
								<text class="Nname">{{item.nickname}}</text>查看了你的房源
							</view>
						</view>
						<view class="right">
							{{item.createtime}}
						</view>
					</view>
					
					<navigator :url="'/pages/me/content/houseDetail?house_id='+item.id">
					<view class="bottom">
						<view class="left">
							
							<image v-if="item.image" :src="siteUrl+item.image" mode="scaleToFill"></image>
							<image v-else :src="siteUrl+item.images.split(',',1)" mode="scaleToFill"></image>
													
						
						
						</view>
						<view class="right">
							<view class="name">{{item.title}}</view>
							<view class="address">{{item.location_near}}</view>
							<!--<view class="tags" >
								<text class="tag" v-for="(tag,ind) in item.tags" :key="ind">{{tag}}</text>
							</view>-->
							<view class="prices">
								<view :class="[item.isActive?'price':'unprice']">{{item.price}}元/月</view>
								<view :style="{display:(item.isActive?'none':'block')}" class="existence">已租</view>
							</view>
							
						</view>
					</view>
					</navigator>
					
				</view>
				<uni-load-more  :loadingType="loadingType" :contentText="contentText" :status="status"></uni-load-more>
				
				
			</view>
		</view>
	</view>
</template>

<script>
	var _self,
	page = 1,
	timer = null;
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue'
	export default {
		components: {
		   uniLoadMore
		},
		data() {
			return {
				siteUrl:this.websiteUrl,
				title: 'index',
				datalist:[],
				status: 'more',
				loadingText: '加载中...',
				loadingType: 2,//定义加载方式 0---contentdown  1---contentrefresh 2---contentnomore
				contentText: {
				    contentdown:'上拉显示更多',
				    contentrefresh: '正在加载...',
				    contentnomore: '没有更多数据了'
				},	
				
			}
		},
		
		onLoad() {
			_self = this
			this.getview()
		},
		onPullDownRefresh: function() {
			//下拉刷新的时候请求一次数据			
		    this.getview()				
		},
		onReachBottom: function() {
			//触底的时候请求数据，即为上拉加载更多
			//为了更加清楚的看到效果，添加了定时器
		    if (timer != null) {
		        clearTimeout(timer);
		    }		   
			 _self.getmorenews()
		},
		
		
		methods: {
			getmorenews: function() {
				if(_self.status !== 'more'){
					return false
				}						    
				_self.status = 'loading'
			    uni.showNavigationBarLoading();//显示加载动画
			    uni.request({
			        url:this.websiteUrl+'/api.php/center/houseView?page='+page,
			        method: 'POST',
					header: {
						'content-type':'application/x-www-form-urlencoded'						
					},
					data: {
						token:uni.getStorageSync('token'),
						
					},					
			        success: function(res) {			           																	
			            if (res.data.data.data.length == 0) {//没有数据			                
							_self.status = 'noMore'							
			                uni.hideNavigationBarLoading();//关闭加载动画							
			                return false;
			            }
			            page++;//每触底一次 page +1										
			            _self.datalist = _self.datalist.concat(res.data.data.data);//将数据拼接在一起			           
						_self.status = 'more'					
			            uni.hideNavigationBarLoading();//关闭加载动画
			        }
			    });
			},
			getview(){
				page = 1;
				_self.status = 'more'
				uni.showNavigationBarLoading();
				uni.request({
					url: this.websiteUrl+'/api.php/center/houseView?page=1',
					method: 'POST',
					header: {
						'content-type':'application/x-www-form-urlencoded'						
					},					
					data: {token:uni.getStorageSync('token')},
					success: function(res){	
						page++
						_self.datalist = res.data.data.data
						uni.hideNavigationBarLoading();
						uni.stopPullDownRefresh();//得到数据后停止下拉刷新	
						
					},
					
				});
			}
		}
	}
</script>

<style>
	.content {
		overflow: hidden;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		/* background: #4F5861; */
	}

	.head_button{
		display: flex;
		justify-content: space-between;
		padding: 60upx 0;
		width: 80%;
	}
	.button_item{
		text-align: center;
	}
	.button_item image{
		width: 100upx;
		height: 100upx;
		border-radius: 50%;
	}
	.button_item .button_text{
		color: white;
		font-size: 28upx;
	}
	.Popular{
		width: 100%;
		/* margin-top: -10upx; */
	}
	.pop_title{
		width: 100%;
		height: 90upx;
		text-align: center;
		font-size: 15upx;
		line-height: 90upx;
		background: white;
		border-radius: 10upx 10upx 0 0;
	}
	.pop_content{
		overflow: hidden;
		width: 100%;
		/* background: white; */
	}
	.pop_item{
		width: 700upx;
		margin: 10upx auto;
		padding: 20upx;
		background: #FFFFFF;
	}
	.pop_item .top{
		display: flex;
		justify-content: space-between;
		height: 100upx;
	}
	.pop_item .top .left{
		margin-top: 10upx;
		display: flex;
		width: 70%;
	}
	.pop_item .top .left image{
		width: 50upx;
		height: 50upx;
		border-radius:50%;
	}
	.pop_item .top .left .text{
		font-size: 26upx;
		line-height: 50upx;
	}
	.pop_item .top .left .text .Nname{
		padding: 0 10upx;
		color: #FF984C;
	}
	.pop_item .top .right{
		margin-top: 10upx;
		width: 30%;
		font-size: 26upx;
		line-height: 50upx;
		text-align: right;
	}
	.pop_item .bottom{
		display: flex;
		justify-content: space-between;
	}
	.pop_item .bottom .left{
		width: 240upx;
		height: 180upx;
	}
	.pop_item .bottom .left image{
		width: 240upx;
		height: 180upx;
	}
	.pop_item .bottom .left .text{
		font-size: 32upx;
		line-height: 180upx;
	}
	.pop_item .bottom .right{
		width: 440upx;
		height: 200upx;
	}
	.pop_item .bottom .right .name{
		width: 100%;
		height: 40upx;
		font-size: 32upx;
	}
	.pop_item .bottom .right .address{
		width: 100%;
		height: 40upx;
		margin: 10upx 0;
		color: #707071;
		font-size: 24upx;
		line-height: 40upx;
	}
	.pop_item .bottom .right .tags{
		display: flex;
	}
	.pop_item .bottom .right .tag{
		padding: 0 5upx;
		margin:0 5upx;
		color: #C0C0C0;
		font-size: 24upx;
		border: solid 1px #C0C0C0;
	}
	.pop_item .bottom .right .prices{
		margin-top: 20upx;
		width: 100%;
		display: flex;
		justify-content: space-between;
	}
	.pop_item .bottom .right .prices .price{
		
		color: #FF4C4C;
		font-size: 30upx;
		line-height: 40upx;
		font-weight: bold;
	}
	.pop_item .bottom .right .prices .unprice{
		
		color: #999999;
		font-size: 30upx;
		line-height: 40upx;
		font-weight: bold;
	}
	.pop_item .bottom .right .prices .existence{
		width: 60upx;
		height: 30upx;
		background: #CCCCCC;
		color: white;
		font-size: 24upx;
		line-height: 30upx;
		text-align: center;
	}
</style>
